#include "Treadmill.h"
#include "TreadMillConstants.h"
#include <sstream>
#include <iomanip>

Treadmill::Treadmill() : state(0), speed(0.0f), incline(0.0f), isPerson(0) {}

Treadmill &Treadmill::getInstance() {
    static Treadmill instance;
    return instance;
}

// =================== 基础属性 ======================

std::string Treadmill::getStateString() const {
    if (state == TreadMillConstants::UCB_STATE_STOPPED) {
        return "STOP";
    } else if (state == TreadMillConstants::UCB_STATE_RUNNING) {
        return "RUNNING";
    } else if (state == TreadMillConstants::UCB_STATE_READY) {
        return "READY";
    } else if (state == TreadMillConstants::UCB_STATE_PAUSED) {
        return "PAUSED";
    } else if (state == TreadMillConstants::UCB_STATE_ERROR) {
        return "ERROR";
    } else if (state == TreadMillConstants::UCB_STATE_STOPPING) {
        return "STOPPING";
    } else {
        return "UNKNOWN";
    }
}

int Treadmill::getState() const {
    return state;
}

void Treadmill::setState(int _state) {
    state = _state;
}

float Treadmill::getSpeed() const {
    return speed;
}

void Treadmill::setSpeed(float _speed) {
    speed = _speed;
}

std::string Treadmill::getSpeedUnit() const {
    if(speedUnit == 0 || speedUnit == 1){
        return "mph/sec";
    } else{
        return "kph/sec";
    }
}

void Treadmill::setSpeedUnit(int _unit) {
    speedUnit = _unit;
}

float Treadmill::getIncline() const {
    return incline / 10.0f;
}

void Treadmill::setIncline(float inc) {
    incline = inc;
}

int Treadmill::getIsPerson() const {
    return isPerson;
}

std::string Treadmill::getIsPersonString() const {
    if(isPerson == 0){
        return "No person";
    } else if(isPerson == 1){
        return "Yes person";
    } else if(isPerson == 2){
        return "Auto stop request";
    }
}

void Treadmill::setIsPerson(int person) {
    isPerson = person;
}

// =================================================

std::string Treadmill::getCalibrationProgress() const {
    if (calibrationProgress == TreadMillConstants::CALIBRATE_PROGRESS_STARTED) {
        return "STARTED";
    } else if (calibrationProgress == TreadMillConstants::CALIBRATE_PROGRESS_INCLINE_UP) {
        return "INCLINE GOING UP";
    } else if (calibrationProgress == TreadMillConstants::CALIBRATE_PROGRESS_INCLINE_DOWN) {
        return "INCLINE GOING DOWN";
    } else if (calibrationProgress == TreadMillConstants::CALIBRATE_PROGRESS_FINISHED) {
        return "FINISHED";
    } else if (calibrationProgress == TreadMillConstants::CALIBRATE_PROGRESS_ERROR) {
        return "ERROR";
    } else {
        return "UNKNOWN";
    }
}

void Treadmill::setCalibrationProgress(int progress) {
    calibrationProgress = progress;
}


int Treadmill::getDiagnosticsOption() const{
    return diagnosticsOption;
}
void Treadmill::setDiagnosticsOption(int option){
    diagnosticsOption = option;
}

int Treadmill::getDiagnosticsProgress() const {
    return diagnosticsProgress;
}

void Treadmill::setDiagnosticsProgress(int progress) {
    diagnosticsProgress = progress;
}

int Treadmill::getErrorData() const { return errorData; }

void Treadmill::setErrorData(int error) { errorData = error; }

